package com.cupk.rotaryguard.monitor.controller;

import com.cupk.common.base.utils.result.Result;
import com.cupk.rotaryguard.monitor.service.WarningService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author tjy
 * @date 2023/4/17
 * @apiNote
 */
@RestController
@RequestMapping("/warning")
public class WarningController {
    @Resource
    private WarningService warningService;


    /**
     * 生成预警
     *
     * @return
     */
    @PostMapping("/generate")
    public Result generateWarning() {
        return warningService.generateWarning();
    }

    /**
     * 获取未处理预警列表
     *
     * @return
     */
    @GetMapping("/list-todo")
    public Result getTodoWarningList(@RequestParam Integer pageNum,@RequestParam Integer pageSize) {
        return warningService.getTodoWarningList(pageNum,pageSize);
    }

    /**
     * 获取预警列表
     *
     * @param pageNum
     * @param pageSize
     * @param deviceId
     * @param deviceModel
     * @param deviceFault
     * @param handlingPerson
     * @return
     */
    @GetMapping("/list")
    public Result getWarningList(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                 @RequestParam(defaultValue = "") Long deviceId,
                                 @RequestParam(defaultValue = "") String deviceModel,
                                 @RequestParam(defaultValue = "") String deviceFault,
                                 @RequestParam(defaultValue = "") String handlingPerson,
                                 @RequestParam(defaultValue = "") Integer handlingStatus) {
        return warningService.getWarningList(pageNum, pageSize, deviceId, deviceModel, deviceFault, handlingPerson, handlingStatus);
    }

    /**
     * 处理预警
     *
     * @param warningId
     * @param username
     * @return
     */
    @PostMapping("/do")
    public Result doWarningRead(@RequestParam Integer warningId, @RequestParam String username) {
        return warningService.doWarningRead(warningId, username);
    }

    /**
     * 根据id 单个删除
     *
     * @param id
     * @return
     */
    @PostMapping("/del/{id}")
    public Result delWarning(@PathVariable Integer id) {
        return warningService.delWarning(id);
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @PostMapping("/del-warnings")
    public Result delWarnings(@RequestBody List<Integer> ids) {
        return warningService.delWarnings(ids);
    }

    /**
     * 获取待处理预警总数
     *
     * @return
     */
    @GetMapping("/count-todo")
    public Result warningTodoCount() {
        return warningService.warningTodoCount();
    }

    /**
     * 获取待处理预警总数
     *
     * @return
     */
    @GetMapping("/count")
    public Result warningCount() {
        return warningService.warningCount();
    }
}
